from datetime import datetime, timedelta, tzinfo, timezone


class BeijingZone(tzinfo):
    def utcoffset(self, dt):
        return timedelta(hours=8)

    def dst(self, dt):
        return timedelta(0)

    def tzname(self, dt):
        return "+08:00"

    def __repr__(self):
        return f"{self.__class__.__name__}()"


def date_now() -> datetime:
    """
    获取的UTC时间，不带时区，用于数据库存储使用
    """
    return datetime.utcnow()


def format_date(d: datetime):
    d = d.replace(tzinfo=timezone.utc)
    return d.isoformat(timespec='seconds')


if __name__ == '__main__':
    pass